package com.tencent.youtufacetrack;

import android.graphics.Bitmap;

import android.content.Context;

import com.loopj.android.http.AsyncHttpClient;
import com.loopj.android.http.AsyncHttpResponseHandler;
import com.loopj.android.http.MySSLSocketFactory;

import org.json.JSONException;
import org.json.JSONObject;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;


import android.content.res.AssetManager;
import android.os.Looper;

import java.util.Timer;
import java.util.TimerTask;

import cz.msebera.android.httpclient.entity.StringEntity;

public class YoutuFaceTrack
{
    private static YoutuFaceTrack instance = null;

    private static long handle = 0;

    public static synchronized YoutuFaceTrack getInstance()
    {
        if (instance == null) {
            instance = new YoutuFaceTrack();
        }
        return instance;
    }

    public static long getHandle(){
        return handle;
    }


    private long nativePtr;

    public YoutuFaceTrack()
    {
        NativeConstructor();
    }

    public void destroy()
    {
        NativeDestructor();
    }

    protected void finalize() throws Throwable
    {
        NativeDestructor();
    }

    public static class FaceStatus
    {
        public float xys[];
        public float pitch;
        public float yaw;
        public float roll;
        public double illumination_score;
    };

    // init
    // panda大佬说，只要能跑起来就不用管它是否爆红
    public native boolean Init(byte[] ufdmtccbin, byte[] ufatbin);

    // return face rect if detected, null otherwise
    public native FaceStatus[] DoDetectionProcessYUV(byte[] yuv420sp, int width, int height);
    public native FaceStatus[] DoDetectionProcessRGBA(byte[] rgba, int width, int height);

    private native void NativeConstructor();
    private native void NativeDestructor();

    static private native boolean nativeInit();
    static {
        System.loadLibrary("YTCommon");
        System.loadLibrary("YTIllumination");
        System.loadLibrary("YTFaceTrackPro");
        System.loadLibrary("facetrackwrap");
        nativeInit();
    }
}
